package student.stu23002142.chapter09;

class Person2{
    private String name;
    private int age;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String toString() {
        return "姓名："+this.name+",年龄："+this.age;
    }
}

public class Demo02 { public static void main(String args[]){
    Class<?> c = null; 				//声明Class类对象c
    try{
        c = Class.forName("student.stu23002142.chapter09.Person2");//调用forName()方法实例化c
    }catch(ClassNotFoundException e){
        e.printStackTrace();
    }
    Person2 per = null;					//声明Person类对象per
    try{
        per = (Person2)c.newInstance();//通过c调用newInstance()方法实例化per
    }catch (Exception e){
        e.printStackTrace();
    }
    per.setName("张三");
    per.setAge(30);
    System.out.println(per);
}
}
